home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kopete / kopeteaccountmanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.6 KB  |  234 lines

  1. /*
  2.     kopeteaccountmanager.h - Kopete Account Manager
  3.  
  4.     Copyright (c) 2002-2003 by Martijn Klingens      <klingens@kde.org>
  5.     Copyright (c) 2003-2004 by Olivier Goffart       <ogoffart@ tiscalinet.be>
  6.  
  7.     Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
  8.  
  9.     *************************************************************************
  10.     *                                                                       *
  11.     * This library is free software; you can redistribute it and/or         *
  12.     * modify it under the terms of the GNU Lesser General Public            *
  13.     * License as published by the Free Software Foundation; either          *
  14.     * version 2 of the License, or (at your option) any later version.      *
  15.     *                                                                       *
  16.     *************************************************************************
  17. */
  18.  
  19. #ifndef __kopeteaccountmanager_h__
  20. #define __kopeteaccountmanager_h__
  21.  
  22. #include <qobject.h>
  23. #include <qptrlist.h>
  24. #include <qdict.h>
  25.  
  26. #include "kopete_export.h"
  27.  
  28.  
  29. namespace Kopete {
  30.  
  31. class Account;
  32. class Plugin;
  33. class Protocol;
  34. class Contact;
  35. class OnlineStatus;
  36.  
  37. /**
  38.  * AccountManager manages all defined accounts in Kopete. You can
  39.  * query them and globally set them all online or offline from here.
  40.  *
  41.  * AccountManager is a singleton, you may uses it with @ref AccountManager::self()
  42.  *
  43.  * @author Martijn Klingens <klingens@kde.org>
  44.  * @author Olivier Goffart <ogoffart@ tiscalinet.be>
  45.  */
  46. class KOPETE_EXPORT AccountManager : public QObject
  47. {
  48.     Q_OBJECT
  49.  
  50. public:
  51.     /**
  52.      * \brief Retrieve the instance of AccountManager.
  53.      *
  54.      * The account manager is a singleton class of which only a single
  55.      * instance will exist. If no manager exists yet this function will
  56.      * create one for you.
  57.      *
  58.      * \return the instance of the AccountManager
  59.      */
  60.     static AccountManager* self();
  61.  
  62.     ~AccountManager();
  63.  
  64.     /**
  65.      * \brief Retrieve the list of accounts
  66.      * \return a list of all the accounts
  67.      */
  68.     const QPtrList<Account> & accounts() const;
  69.  
  70.     /**
  71.      * \brief Retrieve a QDict of accounts for the given protocol
  72.      *
  73.      * The list is guaranteed to contain only accounts for the specified
  74.      * protocol
  75.      * \param p is the Protocol object you want accounts for
  76.      */
  77.     QDict<Account> accounts( const Protocol *p ) const;
  78.  
  79.     /**
  80.      * \brief Return the account asked
  81.      * \param protocolId is the ID for the protocol
  82.      * \param accountId is the ID for the account you want
  83.      * \return the Account object found or NULL if no account was found
  84.      */
  85.     Account* findAccount( const QString &protocolId, const QString &accountId );
  86.  
  87.     /**
  88.      * \brief Delete the account and clean the config data
  89.      *
  90.      * This is praticaly called by the account config page when you remove the account.
  91.      */
  92.     void removeAccount( Account *account );
  93.  
  94.     /**
  95.      * \brief Guess the color for a new account
  96.      *
  97.      * Guesses a color for the next account of a given protocol based on the already registered colors
  98.      * \return the color guessed for the account
  99.      */
  100.     QColor guessColor( Protocol *protocol ) const ;
  101.  
  102.     /**
  103.      * @brief Register the account.
  104.      *
  105.      * This adds the account in the manager's account list.
  106.      * It will check no accounts already exist with the same ID, if any, the account is deleted. and not added
  107.      *
  108.      * @return @p account, or 0L if the account was deleted because id collision
  109.      */
  110.     Account *registerAccount( Account *account );
  111.  
  112.  
  113.     /**
  114.      * Flag to be used in setOnlineStatus
  115.      *
  116.      * @c ConnectIfOffline : if set, this will connect offlines account with the status.
  117.      */
  118.     enum SetOnlineStatusFlag { ConnectIfOffline=0x01 };
  119.  
  120.  
  121. public slots:
  122.     /**
  123.      * \brief Connect all accounts at once.
  124.      *
  125.      * Connect every account if the flag excludeConnect is false
  126.      * @see @ref Account::excludeConnect()
  127.      */
  128.     void connectAll();
  129.  
  130.     /**
  131.      * \brief Disconnect all accounts at once.
  132.      */
  133.     void disconnectAll();
  134.  
  135.     /**
  136.      * @brief Set all accounts a status in the specified category
  137.      *
  138.      * Account that are offline will not be connected, unless the ConnectIfOffline flag is set.
  139.      *
  140.      * @param category is one of the Kopete::OnlineStatusManager::Categories
  141.      * @param awayMessage is the new away message
  142.      * @param flags is a bitmask of SetOnlineStatusFlag
  143.      */
  144.     void setOnlineStatus( /*Kopete::OnlineStatusManager::Categories*/ uint category,
  145.                           const QString& awayMessage = QString::null, uint flags=0);
  146.  
  147.     /**
  148.      * \brief Set all accounts to away at once.
  149.      *
  150.      * All account that are connected, but not invisible will be set to away
  151.      * @see Account::setAway
  152.      * @param awayReason is the away message that will be set.
  153.      * @param away decides whether the message is away/non-away
  154.      */
  155.     void setAwayAll( const QString &awayReason = QString::null, bool away=true );
  156.  
  157.     /**
  158.      * \brief Connect or make available every account.
  159.      * Make all accounts Available, by setting status, and connecting if necessary.
  160.      * Accounts are connected based on their excludeConnect() setting.
  161.      * Accounts which are already connected are controlled regardless of their excludeConnect() setting.
  162.      * This is a slot, so you can connect directly to it from e.g. a KAction.
  163.      * @param awayReason is the away(status) message that will be set.
  164.      */
  165.     void setAvailableAll( const QString &awayReason = QString::null );
  166.  
  167.     /**
  168.      * \internal
  169.      * Save the account data to KConfig
  170.      */
  171.     void save();
  172.  
  173.     /**
  174.      * \internal
  175.      * Load the account data from KConfig
  176.      */
  177.     void load();
  178.  
  179.  
  180.  
  181. signals:
  182.     /**
  183.      * \brief Signals when an account is ready for use
  184.      */
  185.     void accountRegistered( Kopete::Account *account );
  186.  
  187.     /**
  188.      * \brief Signals when an account has been unregistered
  189.      *
  190.      * At this state, we are already in the Account destructor.
  191.      */
  192.     void accountUnregistered( const Kopete::Account *account );
  193.  
  194.     /**
  195.      * \brief An account has changed its onlinestatus
  196.      * Technically this monitors Account::myself() onlinestatus changes
  197.      * \param account Account which changed its onlinestatus
  198.      * \param oldStatus The online status before the change
  199.      * \param newStatus The new online status
  200.      */
  201.     void accountOnlineStatusChanged(Kopete::Account *account,
  202.         const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
  203.  
  204. private:
  205.     /**
  206.      * Private constructor, because we're a singleton
  207.      */
  208.     AccountManager();
  209.  
  210. private slots:
  211.     void slotPluginLoaded( Kopete::Plugin *plugin );
  212.     void slotAccountOnlineStatusChanged(Kopete::Contact *c,
  213.         const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
  214.  
  215.     /**
  216.      * \internal
  217.      * Unregister the account.
  218.      */
  219.     void unregisterAccount( const Kopete::Account *account );
  220.  
  221. private:
  222.     bool isAnyAccountConnected();
  223.     static AccountManager *s_self;
  224.     class Private;
  225.     Private *d;
  226. };
  227.  
  228. } //END namespace Kopete
  229.  
  230.  
  231. #endif
  232.  
  233.  
  234.